<?php
/**
 * Builds up a programmatic model for stacked SQL column definitions clause to be used by CREATE query.
 */
class SQLCreateClause extends AbstractSQLClause {
	public static function getInstance() {
		return new SQLCreateClause();
	}
	
	/**
	 * Adds column to create statement.
	 * 
	 * @example $objColumnDefinition = SQLColumnDefinitionClause::getInstance()->setName("id")->setType("INT",3)->setPrimary()->setAutoIncrement()
	 * @param SQLColumnDefinitionClause $objColumnDefinition
	 * @return SQLCreateClause
	 */
	public function setColumn($objColumnDefinition) {
		$this->tblContents[]=$objColumnDefinition;
		return $this;
	}
	
	/**
	 * Transforms statement into a string where each column definition translated to string is separated by comma and enter.
	 * 
	 * @example id INT(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,\r\n
	 * @see AbstractSQLClause::toString()
	 */
	public function toString() {
		$strOutput = "";
		foreach($this->tblContents as $objColumnDefinition) {
			$strOutput .= $objColumnDefinition->toString().",\r\n";
		}
		return substr($strOutput,0,-3);
	}
}